package com.ruoyi.web.controller.system;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ExamItemsG;
import com.ruoyi.system.service.IExamItemsService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 试题Controller
 * 
 * @author ruoyi
 * @date 2024-03-05
 */
@Controller
@RequestMapping("/system/items")
public class ExamItemsController extends BaseController
{
    private String prefix = "system/items";

    @Autowired
    private IExamItemsService examItemsService;

    @RequiresPermissions("system:items:view")
    @GetMapping()
    public String items()
    {
        return prefix + "/items";
    }

    /**
     * 查询试题列表
     */
    @RequiresPermissions("system:items:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ExamItemsG examItems)
    {
        startPage();
        List<ExamItemsG> list = examItemsService.selectExamItemsList(examItems);
        return getDataTable(list);
    }

    /**
     * 导出试题列表
     */
    @RequiresPermissions("system:items:export")
    @Log(title = "试题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ExamItemsG examItems)
    {
        List<ExamItemsG> list = examItemsService.selectExamItemsList(examItems);
        ExcelUtil<ExamItemsG> util = new ExcelUtil<ExamItemsG>(ExamItemsG.class);
        return util.exportExcel(list, "试题数据");
    }

    /**
     * 新增试题
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存试题
     */
    @RequiresPermissions("system:items:add")
    @Log(title = "试题", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ExamItemsG examItems)
    {
        return toAjax(examItemsService.insertExamItems(examItems));
    }

    /**
     * 修改试题
     */
    @RequiresPermissions("system:items:edit")
    @GetMapping("/edit/{eid}")
    public String edit(@PathVariable("eid") Long eid, ModelMap mmap)
    {
        ExamItemsG examItems = examItemsService.selectExamItemsByEid(eid);
        mmap.put("examItems", examItems);
        return prefix + "/edit";
    }

    /**
     * 修改保存试题
     */
    @RequiresPermissions("system:items:edit")
    @Log(title = "试题", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ExamItemsG examItems)
    {
        return toAjax(examItemsService.updateExamItems(examItems));
    }

    /**
     * 删除试题
     */
    @RequiresPermissions("system:items:remove")
    @Log(title = "试题", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(examItemsService.deleteExamItemsByEids(ids));
    }
}
